package cn.agiledata.bank.common.notice.logic;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import cn.agiledata.bank.common.dao.ActionTypeTemplate;
import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.common.util.DateUtil;
import cn.agiledata.bank.hibernateBean.BankInfo;
import cn.agiledata.bank.hibernateBean.Transaction;

public class TransParamTransferImpl implements TransParamTransfer {
	
	private ActionTypeTemplate actionTypeTemplate;
	

	public void setActionTypeTemplate(ActionTypeTemplate actionTypeTemplate) {
		this.actionTypeTemplate = actionTypeTemplate;
	}


	public Map transfer(Transaction trans) {
		Map vnvMap = new HashMap();
		BigDecimal tranAmount = null;
		BigDecimal debitFee = null;
		BigDecimal creditFee = null;
		BigDecimal creditTrueAmount = null;
		BigDecimal debitTrueAmount = null;
		BankInfo bank = null;
		String sendTime = DateUtil.date2String(new Date());
		String tradeType = "担保交易";
		if(trans.getTradeType().equals(Constant.TRANTYPE_NOASSURE))
			tradeType = "非担保交易" ;
		
		if (trans.getAmount() != null) {
			tranAmount = new BigDecimal(trans.getAmount().doubleValue())
					.setScale(2, BigDecimal.ROUND_HALF_UP);
			if (trans.getDebitFee() != null) {
				debitFee = new BigDecimal(trans.getDebitFee().doubleValue())
						.setScale(2, BigDecimal.ROUND_HALF_UP);
				debitTrueAmount = new BigDecimal(trans.getAmount().doubleValue()
						+ trans.getDebitFee().doubleValue()).setScale(2,
						BigDecimal.ROUND_HALF_UP);
			}
			if (trans.getCreditFee() != null) {
				creditFee = new BigDecimal(trans.getCreditFee().doubleValue())
						.setScale(2, BigDecimal.ROUND_HALF_UP);
				creditTrueAmount = new BigDecimal(trans.getAmount()
						.doubleValue()
						- trans.getCreditFee().doubleValue()).setScale(2,
						BigDecimal.ROUND_HALF_UP);
			}
		}
		
		if(trans.getBankSeq()!=null)
			bank = actionTypeTemplate.getBankInfoById(trans.getBankSeq().toString());
		
		
		vnvMap.put("sendTime", sendTime);//发送时间
		vnvMap.put("tradeType", tradeType);//交易类型，担保交易或者无担保交易
		vnvMap.put("", trans.getAccountBankSeq());
		vnvMap.put("transId", trans.getTransId());//交易号
		vnvMap.put("bankSeq", bank.getBankName());
		
		if(tranAmount != null)
			vnvMap.put("tranAmount", tranAmount.toString());//交易金额（收付款方是一样的）
		
		//付款方
		vnvMap.put("debit", trans.getDebit().getAccount().getName());//付款方姓名
		if(debitFee!= null)
			vnvMap.put("debitFee", debitFee);//付款方费率
		if(debitTrueAmount!=null)
			vnvMap.put("debitTrueAmount", debitTrueAmount.toString());//付款方实际金额
		
		//收款方
		vnvMap.put("credit", trans.getCredit().getAccount().getName());//收款方姓名
		if(creditFee!=null)
			vnvMap.put("creditFee", creditFee);//收款方费率
		if(creditTrueAmount!=null)
			vnvMap.put("creditTrueAmount", creditTrueAmount);//收款方姓名
		return vnvMap;
	}

}
